<?php
include("dbcon.php");
$userip = $_SERVER['REMOTE_ADDR'];

if(@$_REQUEST['value'])
{
	$value = mysql_escape_string($_REQUEST['value']);
	$value = strip_tags($value);
	
	if($value)
	{
		$result = mysql_query("select userip from polling_ip where userip='$userip'");
		$num    = mysql_num_rows($result);
	}
	
	if($num==0)
	{
		if($value == 'good')
		{
			$query = "update polling set liked = liked+1 where id = 1";
		}
		else if($value == 'bad')
		{
			$query = "update polling set dislike = dislike+1 where id = 1";
		}
		else if($value == 'average')
		{
			$query = "update polling set average = average+1 where id = 1";
		}
		
		mysql_query( $query);
		
		$que = "insert into polling_ip (userip) values ('$userip')";
		mysql_query( $que);
	}
	
	$result=mysql_query("select * from polling");
	
	$row=mysql_fetch_array($result);
	//$gettotal = mysql_num_rows($result);
	
	$gettotal = $row['dislike'] + $row['liked'];
	
	$dislike=$row['dislike'];
	
	$like=$row['liked'];
	
	$average=$row['average'];
	
	$likes=($like*30)/$gettotal;
	$average=($average*30)/$gettotal;
	$dislikes=($dislike*30)/$gettotal;;?>

	<div id="poll_result">
		
		<label style="margin-left:22px;"> Good </label> <label> Bad </label><label> Average </label>
		<br clear="all" />
		
		<div class="greenBar2" style="height:<?php echo $likes?>px">&nbsp;</div>
		
		<div class="redbar2" style="height:<?php echo $dislikes?>px">&nbsp;</div>
		
		<div class="bluebar2" style="height:<?php echo $average?>px">&nbsp;</div>
		
		<br clear="all" />
		<br clear="all" />
	</div>
	<?php
}?>

